package john.wenzi.server.servlet;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

import john.wenzi.server.entity.FileUploadEntity;
import john.wenzi.server.service.Impl.FileUploadServiceImpl;

public class FindFileServlet extends HttpServlet{
	
	private static final long serialVersionUID = 1L;
	public static Logger logger = LoggerFactory.getLogger(FindFileServlet.class);
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info("查询文件信息开始");
		request.setCharacterEncoding("utf-8"); 
	    response.setCharacterEncoding("utf-8"); 
	    FileUploadServiceImpl fileUploadServiceImpl = new FileUploadServiceImpl(); 
	    String fileName = request.getHeader("fileName");
	    logger.info("查询文件信息参数："+fileName);
	    try {
			FileUploadEntity fileUploadEntity = fileUploadServiceImpl.findUploadRecord(fileName);
			logger.info("查询文件信息结果："+fileUploadEntity.toString());
			String json = JSON.toJSONString(fileUploadEntity);
			response.getWriter().write(json);
			logger.info("查询文件信息成功");
		} catch (Exception e) {
			logger.info("查询文件信息出现异常："+e.getMessage());
			e.printStackTrace();
		}
	    
	}

}
